package com.tarena.lbs.marketing.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.marketing.web.service.UserCouponsService;
import com.tarena.lbs.pojo.marketing.param.UserCouponsParam;
import com.tarena.lbs.pojo.marketing.po.UserCouponsPO;
import com.tarena.lbs.pojo.marketing.query.UserCouponCodeQuery;
import com.tarena.lbs.pojo.marketing.query.UserCouponQuery;
import com.tarena.lbs.pojo.marketing.vo.UserCouponsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

//处理用户领取的优惠券相关业务
//领 查
@RestController
public class UserCouponsController {
    @Autowired
    private UserCouponsService userCouponsService;
    //小程序用户 领取查看到的某个优惠券--实际领取的是券码
    @PostMapping("/marketing/user/receive/save")
    public Result<Void> receiveCoupon(@RequestBody UserCouponsParam param)
        throws BusinessException{
        userCouponsService.receiveCoupon(param);
        return Result.success();
    }

    //小程序 查询当前登录用户的领取优惠券列表
    @PostMapping("/marketing/user/receive/list")
    public Result<PageResult<UserCouponsVO>> showMyCoupons(@RequestBody UserCouponQuery query)
            throws BusinessException{
        PageResult<UserCouponsVO> voPage=userCouponsService.showMyCoupons(query);
        return new Result<>(voPage);
    }
    //查询我的优惠码详情
    @PostMapping("/marketing/user/receive/detail")
    public Result<UserCouponsVO> showCouponDetail
    (@RequestBody UserCouponCodeQuery query)throws BusinessException{
        UserCouponsVO vo=userCouponsService.userCouponDetail(query);
        return new Result<>(vo);
    }
}
